#include "opencv2/opencv.hpp"
#include <iostream>
#include <opencv2/imgproc/types_c.h>
#include <opencv2/imgproc.hpp>

using namespace std;
using namespace cv;

Mat imgProc(Mat imgIn) {
    Mat imgOut;
    imgIn.copyTo(imgOut);
    int thre = 80, maxv = 155;
    Mat dst;

    
    vector<Mat> channels;
    split(imgOut, channels);
    channels[1]=Scalar(0);
    channels[0]=Scalar(0);
    merge(channels,imgOut);  

    GaussianBlur(imgOut, imgOut, Size(3, 3), 3, 3);
    Canny(imgOut, dst, 80, 500, 3);

    floodFill(dst, Point(5, 50), Scalar(255), 0, FLOODFILL_FIXED_RANGE);

    return dst;
}

void imageIO() {
    //input image path
    string imgPath;
    cout << "Select a file to Open: \n";
    cin >> imgPath;

    //Ctrl + D
    if(imgPath.empty()) imgPath = "../TestFiles/Energy02.jpg";

    //read image
    Mat img = imread(imgPath);
    Mat dst;

    //show image
    imshow("Display Image", imgProc(img));
    //imshow("Display Image2", dst);
    //quit
    while(waitKey(0) != 'q') cout << "Press Q to Quit\n";//ASCII
}

int main() {
    imageIO();
    imwrite("Pretreat.jpg", imgProc(imread("TestFiles/Energy02.jpg")));
    return 0;
}